#pragma once

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define PROPERTY_STRING(name, def_value) \
	__declspec(property(get = get_##name, put = put_##name)) CString name;\
	CString get_##name() const { ATLASSERT(keyRegistry.IsValid());  CString value; if (!keyRegistry.QueryValue( _T(#name), value )) return _T(def_value); return value; } \
	void put_##name(const CString &value) { ATLASSERT(keyRegistry.IsValid()); keyRegistry.SetValue( _T(#name), value ); } 

#define PROPERTY_DWORD(name, def_value) \
	__declspec(property(get = get_##name, put = put_##name)) DWORD name;\
	DWORD get_##name() const { ATLASSERT(keyRegistry.IsValid());  DWORD value; if (!keyRegistry.QueryValue( _T(#name), value )) return def_value; return value; } \
	void put_##name(DWORD value) { ATLASSERT(keyRegistry.IsValid()); keyRegistry.SetValue( _T(#name), value ); } 

#define PROPERTY_DWORD_EX(name, def_value, begin_value, end_value) \
	__declspec(property(get = get_##name, put = put_##name)) DWORD name;\
	DWORD get_##name() const { ATLASSERT(keyRegistry.IsValid());  DWORD value; if (!keyRegistry.QueryValue( _T(#name), value ) || value < begin_value || value > end_value) return def_value; return value; } \
	void put_##name(DWORD value) { ATLASSERT(keyRegistry.IsValid()); keyRegistry.SetValue( _T(#name), value ); } 

#define PROPERTY_BOOL(name, def_value) \
	__declspec(property(get = get_##name, put = put_##name)) bool name;\
	bool get_##name() const { ATLASSERT(keyRegistry.IsValid());  bool value; if (!keyRegistry.QueryValue( _T(#name), value )) return def_value; return value; } \
	void put_##name(bool value) { ATLASSERT(keyRegistry.IsValid()); keyRegistry.SetValue( _T(#name), value ); } 

#define PROPERTY_LONGLONG(name, def_value) \
	__declspec(property(get = get_##name, put = put_##name)) LONGLONG name;\
	LONGLONG get_##name() const { ATLASSERT(keyRegistry.IsValid());  LONGLONG value; if (!keyRegistry.QueryValue( _T(#name), value )) return def_value; return value; } \
	void put_##name(LONGLONG value) { ATLASSERT(keyRegistry.IsValid()); keyRegistry.SetValue( _T(#name), value ); } 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Configuration
//

class Configuration
{
private:
	RegKey keyRegistry;

public:
	Configuration(void)
	{
		LPCTSTR pszKey;

		if (IsOSVistaOrHigher())
			pszKey = _T("Software\\Microsoft\\Internet Explorer\\LowRegistry\\" _PROJECT_REGKEY);
		else
			pszKey = _T("Software\\" _PROJECT_REGKEY);

		if (!keyRegistry.CreateEx(HKEY_CURRENT_USER, pszKey))
			return;
	}

	// write logs
	PROPERTY_BOOL(log, false)
	// check for updates 1 (days)
	PROPERTY_DWORD(checkForUpdateInterval, 3)
	PROPERTY_LONGLONG(lastCheckForUpdateTime, 0)
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
